package jdbc;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

/**
 * @Author admin
 * @Date 2019/4/26 8:15
 */
public class Test {
    static BookDB dao = new BookDB();
    static Scanner  in = new Scanner(System.in);
    static Scanner inDouble=new Scanner(System.in);
    public static void main(String[] args) {
             while (true){
                 System.out.println("欢迎进入图书管理系统");
                 System.out.println("1--保存图书信息");
                 System.out.println("2--查询图书信息");
                 System.out.println("3--查询图书信息");
                 System.out.println("4--删除图书信息");
                 System.out.println("5--退出");
                 System.out.println("请输入你的选择：");
                 int chose = inDouble.nextInt();
                 switch (chose){
                     case 1:
                         insertUI();
                         break;
                     case 2:
                         selectUI();
                         break;
                     case 3:
                         updateUI();
                         break;
                     case 4:
                         queryUI();
                         break;
                     case 5:
                         exitUI();
                         break;
                 }

             }
    }
    private static void insertUI(){
        System.out.println("请输入图书名称：");
        String name = in.nextLine();
        System.out.println("请输入出版社：");
        String press = in.nextLine();
        System.out.println("请输入作者：");
        String author=in.nextLine();
        System.out.println("请输入价格：");
        Double price=inDouble.nextDouble();
        Book book = new Book(name,press,author,price);
        int c = dao.insert(book);
        if (c>0){
            System.out.println("添加成功");
        }else{
            System.out.println("添加失败");
        }
    }
    private static void selectUI(){
        System.out.println("--------------所有图书信息如下------------");
        System.out.println("编号\t书名\t出版社\t作者\t价格");
        /*查询返回，返回保存图书对象的集合*/
        ArrayList<Book> arrayList = dao.selectAll();
        /*遍历集合，展示图书信息*/
        Iterator<Book> iterator = arrayList.iterator();
        while (iterator.hasNext()){
            Book book =iterator.next();
            System.out.println(book.getId()+"\t"+book.getPress()+"\t"+book.getAuthor()+"\t"+book.getPrice());
        }
    }
    private static void updateUI(){
        System.out.println("-----更新界面-----");
    }
    private static void exitUI(){

    }
    private static void queryUI(){
        dao.query();
    }

}
